package edu.tec.mty.extras;

import edu.tec.mty.extras.Vector2D;

public class Vector2D {

	private double dx;
	private double dy;
	
	public Vector2D(double dx, double dy) {
		this.dx = dx;
		this.dy = dy;
	}
	
	/**
	 * Construct a new instance of Vector2D with x and y components
	 * @param x
	 * @param y
	 * @return
	 */
	public static Vector2D getVectorWithXAndY(double x, double y) {
		return new Vector2D(x, y);
	}
	
	/**
	 * Construct a new instance of Vector2D with magnitude and direction
	 * @param magnitude
	 * @param direction
	 * @return A Vector2D with mgnitude and direction
	 */
	public static Vector2D getVectorWithMagnitudeAndDirection(double magnitude, double direction) {
		double x = magnitude * Math.cos(Math.toRadians(direction));
		double y = magnitude * Math.sin(Math.toRadians(direction));
		return new Vector2D(x, y);
	}
	
	public double getXComponent() {
		return this.dx;
	}
	
	public double getYComponent() {
		return this.dy;
	}
	
	public double getMagnitude() {
		return Math.sqrt(Math.pow(dx, 2.0) + Math.pow(dy, 2.0));
	}
	
	public double getDirection() {
		return Math.toDegrees(Math.atan2(dy, dx));
	}
	
}
